home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <GL/glx.h>
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <X11/keysym.h>
- #include <math.h>
- #include <sys/types.h>
- #include <time.h>
-
- static int RGB_attributes[] = {
- GLX_RGBA,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- None,
- };
-
- static int CI_attributes[] = {
- None,
- };
-
- int rgb = 1;
-
- #define PIXEL_CENTER(x) ((long) (x) + 0.5)
- #define SETCOLOR(x) (rgb ? glColor3fv(rgbMap[x]) : glIndexf(x))
-
- enum {
- BLACK = 0,
- RED,
- GREEN,
- YELLOW,
- BLUE,
- MAGENTA,
- CYAN,
- WHITE
- };
-
- static float rgbMap[8][3] = {
- {0, 0, 0},
- {1, 0, 0},
- {0, 1, 0},
- {1, 1, 0},
- {0, 0, 1},
- {1, 0, 1},
- {0, 1, 1},
- {1, 1, 1}
- };
-
-
- #define GAP 10
- #define ROWS 3
- #define COLS 4
-
- static long W = COLS*100 + (COLS + 1)*GAP;
- static long H = ROWS*100 + (ROWS + 1)*GAP;
- static long boxW = 100;
- static long boxH = 100;
- static long drawBuffer = GL_FRONT;
- static int randomVertex = 0;
- static int clipped = 0;
- static int fastest2D = 0;
- static int xoffset, yoffset;
-
- static void Viewport(long row, long column)
- {
- long x, y;
-
- x = GAP + column * (boxW + GAP);
- y = GAP + row * (boxH + GAP);
-
- glDrawBuffer(GL_FRONT);
-
- glEnable(GL_SCISSOR_TEST);
- glScissor(x, y, boxW, boxH);
-
- glPushAttrib(GL_COLOR_BUFFER_BIT);
- glColorMask(1, 1, 1, 1);
- glIndexMask(~0);
- glClear(GL_COLOR_BUFFER_BIT);
- glPopAttrib();
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- xoffset = yoffset = 0;
- if (clipped) {
- glViewport(x+boxW/2, y+boxH/2, boxW/2, boxH/2);
- glOrtho(0, boxW/2, 0, boxH/2, -1.0, 1.0);
- } else {
- if (fastest2D) {
- xoffset = x + boxW/2;
- yoffset = y + boxH/2;
- glViewport(0, 0, W, H);
- glOrtho(0, W, 0, H, -1, 1);
- } else {
- glViewport(x, y, boxW, boxH);
- glOrtho(-boxW/2, boxW/2, -boxH/2, boxH/2, -1.0, 1.0);
- }
- }
- glMatrixMode(GL_MODELVIEW);
-
- glDrawBuffer(drawBuffer);
- }
-
- static void myVertex(float x, float y)
- {
- if (fastest2D) {
- x += xoffset;
- y += yoffset;
- }
- if (randomVertex) {
- switch(random() % 3) {
- case 0:
- glVertex2f(x,y);
- break;
- case 1:
- glVertex3f(x,y,0);
- break;
- case 2:
- glVertex4f(x,y,0,1);
- break;
- }
- } else {
- glVertex2f(x,y);
- }
- }
-
- static void Point(void)
- {
- long i;
-
- SETCOLOR(WHITE);
- glBegin(GL_POINTS);
- myVertex(0, 0);
- for (i = 1; i < 8; i++) {
- long j = i * 2;
- SETCOLOR(i);
- myVertex(-j, -j);
- myVertex(-j, 0);
- myVertex(-j, j);
- myVertex(0, j);
- myVertex(j, j);
- myVertex(j, 0);
- myVertex(j, -j);
- myVertex(0, -j);
- }
- glEnd();
- }
-
- static void Lines(void)
- {
- long i;
-
- glPushMatrix();
- glTranslatef(-12, 0, 0);
- for (i = 1; i < 8; i++) {
- SETCOLOR(i);
- glBegin(GL_LINES);
- myVertex(-boxW/4, -boxH/4);
- myVertex(boxW/4, boxH/4);
- glEnd();
- glTranslatef(4, 0, 0);
- }
- glPopMatrix();
-
- /*
- ** Draw a single vertex line to make sure nothing bad happens
- */
- glBegin(GL_LINES);
- myVertex(0, 0);
- glEnd();
- }
-
- static void LineStrip(void)
- {
- glBegin(GL_LINE_STRIP);
- SETCOLOR(RED);
- myVertex(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(-boxH/4));
- SETCOLOR(GREEN);
- myVertex(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(boxH/4));
- SETCOLOR(BLUE);
- myVertex(PIXEL_CENTER(boxW/4), PIXEL_CENTER(boxH/4));
- SETCOLOR(WHITE);
- myVertex(PIXEL_CENTER(boxW/4), PIXEL_CENTER(-boxH/4));
- glEnd();
-
- /*
- ** Draw a single vertex line to make sure nothing bad happens
- */
- glBegin(GL_LINE_STRIP);
- myVertex(0, 0);
- glEnd();
- }
-
- static void LineLoop(void)
- {
- glBegin(GL_LINE_LOOP);
- SETCOLOR(RED);
- myVertex(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(-boxH/4));
- SETCOLOR(GREEN);
- myVertex(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(boxH/4));
- SETCOLOR(BLUE);
- myVertex(PIXEL_CENTER(boxW/4), PIXEL_CENTER(boxH/4));
- SETCOLOR(WHITE);
- myVertex(PIXEL_CENTER(boxW/4), PIXEL_CENTER(-boxH/4));
- glEnd();
-
- /*
- ** Draw a two vertex line with XOR on to make sure that only the
- ** endpoints show. Since each line segment is drawn half-open,
- ** the endpoints will not be drawn twice, thus leaving the XOR of
- ** white in the color buffer. When using an RGB color buffer, use
- ** the blend function to approximate the effects of the XOR.
- */
- glEnable(GL_LOGIC_OP);
- glEnable(GL_BLEND);
- glLogicOp(GL_XOR);
- glBlendFunc(GL_ONE, GL_ONE);
- SETCOLOR(MAGENTA);
- /* this line is vertical */
- glBegin(GL_LINE_LOOP);
- myVertex(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(-boxH/8));
- myVertex(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(boxH/8));
- glEnd();
- /* this line is horizontal */
- glBegin(GL_LINE_LOOP);
- myVertex(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(boxH/8+5));
- myVertex(PIXEL_CENTER(boxW/8), PIXEL_CENTER(boxH/8+5));
- glEnd();
- glDisable(GL_LOGIC_OP);
- glDisable(GL_BLEND);
-
- /*
- ** Draw a point at the center of the area so that we can count pixels
- ** if needed.
- */
- SETCOLOR(GREEN);
- glBegin(GL_POINTS);
- myVertex(0, 0);
- glEnd();
-
- /*
- ** Draw a single vertex line to make sure nothing bad happens
- */
- glBegin(GL_LINE_LOOP);
- myVertex(0, 0);
- glEnd();
- }
-
- #define OPENGL_WIDTH 48
- #define OPENGL_HEIGHT 13
- static GLubyte OpenGL_bits[] = {
- 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
- 0x7f, 0xfb, 0xff, 0xff, 0xff, 0x01,
- 0x7f, 0xfb, 0xff, 0xff, 0xff, 0x01,
- 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
- 0x3e, 0x8f, 0xb7, 0xf9, 0xfc, 0x01,
- 0x63, 0xdb, 0xb0, 0x8d, 0x0d, 0x00,
- 0x63, 0xdb, 0xb7, 0x8d, 0x0d, 0x00,
- 0x63, 0xdb, 0xb6, 0x8d, 0x0d, 0x00,
- 0x63, 0x8f, 0xf3, 0xcc, 0x0d, 0x00,
- 0x63, 0x00, 0x00, 0x0c, 0x4c, 0x0a,
- 0x63, 0x00, 0x00, 0x0c, 0x4c, 0x0e,
- 0x63, 0x00, 0x00, 0x8c, 0xed, 0x0e,
- 0x3e, 0x00, 0x00, 0xf8, 0x0c, 0x00,
- };
-
- static void Bitmap(void)
- {
- static const long xOrigin = 0;
- static const long yOrigin = 3;
-
- /*
- ** Draw some lines showing the left and bottom edges of the bitmap.
- ** The red line is the vertical left edge of the bitmap. The blue
- ** line is the horizontal bottom edge of the bitmap. The yellow line
- ** is the horizontal base line of the bitmap. The green lines mark
- ** where the rasterpos will translate to. Take into account the x
- ** origin.
- */
- glBegin(GL_LINES);
- SETCOLOR(GREEN);
- myVertex(-boxW/2, 0);
- myVertex(boxW/2, 0);
- myVertex(0, -boxH/2);
- myVertex(0, boxH/2);
- SETCOLOR(RED);
- myVertex(-xOrigin, -yOrigin);
- myVertex(-xOrigin, -yOrigin+OPENGL_HEIGHT);
- SETCOLOR(BLUE);
- myVertex(-xOrigin, -yOrigin);
- myVertex(-xOrigin+OPENGL_WIDTH, -yOrigin);
- glEnd();
-
- SETCOLOR(GREEN);
-
- glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-
- glRasterPos2i(xoffset, yoffset);
- glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, xOrigin, yOrigin, 0.0, 0.0,
- OpenGL_bits);
- }
-
- static void Triangles(void)
- {
- glBegin(GL_TRIANGLES);
- SETCOLOR(GREEN);
- myVertex(-boxW/4, -boxH/4);
- SETCOLOR(RED);
- myVertex(-boxW/8, -boxH/16);
- SETCOLOR(BLUE);
- myVertex(boxW/8, -boxH/16);
-
- SETCOLOR(GREEN);
- myVertex(-boxW/4, boxH/4);
- SETCOLOR(RED);
- myVertex(-boxW/8, boxH/16);
- SETCOLOR(BLUE);
- myVertex(boxW/8, boxH/16);
- glEnd();
-
- /*
- ** Generate a 2 vertex triangle that should draw nothing
- */
- glBegin(GL_TRIANGLES);
- myVertex(0, 0);
- myVertex(-100, 100);
- glEnd();
- }
-
- static void TriangleStrip(void)
- {
- glBegin(GL_TRIANGLE_STRIP);
- SETCOLOR(GREEN);
- myVertex(-boxW/4, -boxH/4);
- SETCOLOR(RED);
- myVertex(-boxW/4, boxH/4);
- SETCOLOR(BLUE);
- myVertex(0, -boxH/4);
- SETCOLOR(WHITE);
- myVertex(0, boxH/4);
- SETCOLOR(CYAN);
- myVertex(boxW/4, -boxH/4);
- SETCOLOR(YELLOW);
- myVertex(boxW/4, boxH/4);
- glEnd();
-
- /*
- ** Generate a 2 vertex triangle strip that should draw nothing
- */
- glBegin(GL_TRIANGLE_STRIP);
- myVertex(0, 0);
- myVertex(-100, 100);
- glEnd();
- }
-
- static void TriangleFan(void)
- {
- long x0, x1, x2, x3;
- long y0, y1, y2, y3;
- long vx[8][2];
- long i;
-
- /*
- ** Construct an 8 sided convex polygon that is almost an octahedron
- */
- y0 = -boxH/4;
- y1 = y0 + boxH/2/3;
- y2 = y1 + boxH/2/3;
- y3 = boxH/4;
- x0 = -boxW/4;
- x1 = x0 + boxW/2/3;
- x2 = x1 + boxW/2/3;
- x3 = boxW/4;
-
- vx[0][0] = x0; vx[0][1] = y1;
- vx[1][0] = x0; vx[1][1] = y2;
- vx[2][0] = x1; vx[2][1] = y3;
- vx[3][0] = x2; vx[3][1] = y3;
- vx[4][0] = x3; vx[4][1] = y2;
- vx[5][0] = x3; vx[5][1] = y1;
- vx[6][0] = x2; vx[6][1] = y0;
- vx[7][0] = x1; vx[7][1] = y0;
-
- /*
- ** Draw the polygon, shaded. This will draw the same shape that the
- ** polygon test draws, except that when flat shaded it should draw
- ** entirely white. When smooth shaded it will shade differently
- ** than the polygon test.
- */
- glBegin(GL_TRIANGLE_FAN);
- SETCOLOR(WHITE);
- myVertex(0, 0);
- for (i = 0; i < 8; i++) {
- SETCOLOR(7-i);
- myVertex(vx[i][0], vx[i][1]);
- }
- glEnd();
-
- /*
- ** Generate a 2 vertex triangle fan that should draw nothing
- */
- glBegin(GL_TRIANGLE_FAN);
- myVertex(0, 0);
- myVertex(-100, 100);
- glEnd();
- }
-
- static void Rect(void)
- {
- SETCOLOR(GREEN);
- glRecti(xoffset-boxW/4, yoffset-boxH/4, xoffset+boxW/4, yoffset+boxH/4);
- }
-
- static void Polygon(void)
- {
- long x0, x1, x2, x3;
- long y0, y1, y2, y3;
- long vx[8][2];
- long i;
-
- /*
- ** Construct an 8 sided convex polygon that is almost an octahedron
- */
- y0 = -boxH/4;
- y1 = y0 + boxH/2/3;
- y2 = y1 + boxH/2/3;
- y3 = boxH/4;
- x0 = -boxW/4;
- x1 = x0 + boxW/2/3;
- x2 = x1 + boxW/2/3;
- x3 = boxW/4;
-
- vx[0][0] = x0; vx[0][1] = y1;
- vx[1][0] = x0; vx[1][1] = y2;
- vx[2][0] = x1; vx[2][1] = y3;
- vx[3][0] = x2; vx[3][1] = y3;
- vx[4][0] = x3; vx[4][1] = y2;
- vx[5][0] = x3; vx[5][1] = y1;
- vx[6][0] = x2; vx[6][1] = y0;
- vx[7][0] = x1; vx[7][1] = y0;
-
- /*
- ** Draw the polygon, shaded.
- */
- glBegin(GL_POLYGON);
- for (i = 0; i < 8; i++) {
- SETCOLOR(7-i);
- myVertex(vx[i][0], vx[i][1]);
- }
- glEnd();
-
- /*
- ** Generate a 2 vertex polygon that should draw nothing
- */
- glBegin(GL_POLYGON);
- myVertex(0, 0);
- myVertex(100, 100);
- glEnd();
- }
-
- static void Quads(void)
- {
- glBegin(GL_QUADS);
- SETCOLOR(GREEN);
- myVertex(-boxW/4, -boxH/4);
- SETCOLOR(RED);
- myVertex(-boxW/8, -boxH/16);
- SETCOLOR(BLUE);
- myVertex(boxW/8, -boxH/16);
- SETCOLOR(WHITE);
- myVertex(boxW/4, -boxH/4);
-
- SETCOLOR(GREEN);
- myVertex(-boxW/4, boxH/4);
- SETCOLOR(RED);
- myVertex(-boxW/8, boxH/16);
- SETCOLOR(BLUE);
- myVertex(boxW/8, boxH/16);
- SETCOLOR(WHITE);
- myVertex(boxW/4, boxH/4);
- glEnd();
-
- /*
- ** Generate a 3 vertex quad that should draw nothing
- */
- glBegin(GL_QUADS);
- myVertex(0, 0);
- myVertex(100, 100);
- myVertex(-100, 100);
- glEnd();
- }
-
- static void QuadStrip(void)
- {
- glBegin(GL_QUAD_STRIP);
- SETCOLOR(GREEN);
- myVertex(-boxW/4, -boxH/4);
- SETCOLOR(RED);
- myVertex(-boxW/4, boxH/4);
- SETCOLOR(BLUE);
- myVertex(0, -boxH/4);
- SETCOLOR(WHITE);
- myVertex(0, boxH/4);
- SETCOLOR(CYAN);
- myVertex(boxW/4, -boxH/4);
- SETCOLOR(YELLOW);
- myVertex(boxW/4, boxH/4);
- glEnd();
-
- /*
- ** Generate a 3 vertex quad strip that should draw nothing
- */
- glBegin(GL_QUAD_STRIP);
- myVertex(0, 0);
- myVertex(100, 100);
- myVertex(-100, 100);
- glEnd();
- }
-
- static void RotateColorMask(void)
- {
- static long rotation=0;
-
- rotation = (rotation + 1) & 0x3;
- switch (rotation) {
- case 0:
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glIndexMask( 0xff );
- break;
- case 1:
- /* mask off red */
- glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
- glIndexMask( 0xfe );
- break;
- case 2:
- /* mask off green */
- glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE);
- glIndexMask( 0xfd );
- break;
- case 3:
- /* mask off blue */
- glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
- glIndexMask( 0xfb );
- break;
- }
- }
-
- static void DoTests(void)
- {
- Viewport(0, 0); Point();
- Viewport(0, 1); Lines();
- Viewport(0, 2); LineStrip();
- Viewport(0, 3); LineLoop();
-
- Viewport(1, 0); Bitmap();
- Viewport(1, 1); TriangleFan();
- Viewport(1, 2); Triangles();
- Viewport(1, 3); TriangleStrip();
-
- Viewport(2, 0); Rect();
- Viewport(2, 1); Polygon();
- Viewport(2, 2); Quads();
- Viewport(2, 3); QuadStrip();
-
- glFlush();
- }
-
- static void Usage(void)
- {
- printf("Usage: tprim [-c]\n");
- printf(" -c: Run in color index mode\n");
- exit(-1);
- }
-
- static Bool WaitForMapNotify(Display *d, XEvent *e, char *arg)
- {
- if ((e->type == MapNotify) && (e->xmap.window == (Window)arg)) {
- return GL_TRUE;
- }
- return GL_FALSE;
- }
-
- int main(int argc, char** argv)
- {
- XVisualInfo *vi;
- Display *dpy;
- Colormap cmap;
- Window window;
- XSetWindowAttributes swa;
- GLXContext cx;
- XEvent event;
- GLboolean needDisplay;
- XColor white;
- char *geometry = NULL;
- XSizeHints sizehints;
- int i;
-
- srandom(time(NULL));
- rgb = 1;
- for (i = 1; i < argc; i++) {
- if (!strcmp(argv[i], "-geometry")) {
- i++;
- geometry = argv[i];
- } else if (argv[i][0] == '-') {
- switch (argv[i][1]) {
- case 'c':
- rgb = GL_FALSE;
- break;
- default:
- Usage();
- }
- } else {
- Usage();
- }
- }
-
- dpy = XOpenDisplay(0);
- if (!dpy) {
- fprintf(stderr, "Can't connect to display \"%s\"\n", getenv("DISPLAY"));
- return -1;
- }
-
- vi = glXChooseVisual(dpy, DefaultScreen(dpy),
- rgb ? RGB_attributes : CI_attributes);
- if (!vi) {
- fprintf(stderr, "No singlebuffered rgba visual on \"%s\"\n",
- getenv("DISPLAY"));
- return -1;
- }
-
- cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual,
- rgb ? AllocNone : AllocAll);
- if (rgb) {
- white.red = ~0;
- white.green = ~0;
- white.blue = ~0;
- XAllocColor(dpy, cmap, &white);
- swa.background_pixel = white.pixel;
- } else {
- swa.background_pixel = 7;
- }
-
- if (!rgb) {
- XColor buf;
- int i;
-
- buf.flags = DoRed | DoGreen | DoBlue;
-
- /* Init color map */
- for (i=0; i<16; i++) {
- buf.pixel = i;
- buf.blue = (i & 4) ? 65535 : 0;
- buf.green = (i & 2) ? 65535 : 0;
- buf.red = (i & 1) ? 65535 : 0;
- if (i > 8) {
- buf.red /= 2;
- buf.green /= 2;
- buf.blue /= 2;
- }
- XStoreColor(dpy, cmap, &buf);
- }
- }
-
- sizehints.flags = PPosition | PSize;
- sizehints.width = W;
- sizehints.height = H;
- sizehints.x = 10;
- sizehints.y = 10;
- if(geometry) {
- int flags, x, y, width, height;
-
- flags = XParseGeometry(geometry, &x, &y,
- (unsigned int *)&width,
- (unsigned int *)&height);
- if(WidthValue & flags) {
- sizehints.flags |= USSize;
- sizehints.width = width;
- W = width;
- }
- if(HeightValue & flags) {
- sizehints.flags |= USSize;
- sizehints.height = height;
- H = height;
- }
- if(XValue & flags) {
- if(XNegative & flags)
- x = DisplayWidth(dpy, DefaultScreen(dpy)) + x
- - sizehints.width;
- sizehints.flags |= USPosition;
- sizehints.x = x;
- }
- if(YValue & flags) {
- if(YNegative & flags)
- y = DisplayHeight(dpy, DefaultScreen(dpy)) + y
- - sizehints.height;
- sizehints.flags |= USPosition;
- sizehints.y = y;
- }
- }
- swa.border_pixel = 0;
- swa.background_pixel = white.pixel;
- swa.colormap = cmap;
- swa.event_mask = ExposureMask | StructureNotifyMask | KeyPressMask
- | KeyReleaseMask;
- window = XCreateWindow(dpy, RootWindow(dpy, vi->screen),
- sizehints.x, sizehints.y,
- sizehints.width, sizehints.height,
- 0, vi->depth, InputOutput, vi->visual,
- CWBackPixel|CWBorderPixel|CWColormap|CWEventMask,
- &swa);
- XSetStandardProperties(dpy, window, rgb ? "tprim RGB" : "tprim CI", "tprim",
- None, argv, argc, &sizehints);
- XSetWMColormapWindows(dpy, window, &window, 1);
- XMapWindow(dpy, window);
- XIfEvent(dpy, &event, WaitForMapNotify, (char*)window);
-
- cx = glXCreateContext(dpy, vi, 0, GL_TRUE);
- if (!glXMakeCurrent(dpy, window, cx)) {
- fprintf(stderr, "Can't make window current to context\n");
- return -1;
- }
-
- if (rgb) {
- glClearColor(1, 1, 1, 1);
- } else {
- glClearIndex(7);
- }
- glClear(GL_COLOR_BUFFER_BIT);
- if (rgb) {
- glClearColor(0, 0, 0, 0);
- } else {
- glClearIndex(0);
- }
-
- needDisplay = GL_TRUE;
- for (;;) {
- do {
- XNextEvent(dpy, &event);
- switch (event.type) {
- case Expose:
- needDisplay = GL_TRUE;
- break;
- case ConfigureNotify:
- W = event.xconfigure.width;
- H = event.xconfigure.height;
- needDisplay = GL_TRUE;
- break;
- case KeyPress:
- {
- char buf[100];
- int rv;
- KeySym ks;
-
- rv = XLookupString(&event.xkey, buf, sizeof(buf), &ks, 0);
- switch (ks) {
- case XK_F:
- case XK_f:
- glShadeModel(GL_FLAT);
- needDisplay = GL_TRUE;
- break;
- case XK_S:
- case XK_s:
- glShadeModel(GL_SMOOTH);
- needDisplay = GL_TRUE;
- break;
- case XK_P:
- case XK_p:
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- needDisplay = GL_TRUE;
- break;
- case XK_L:
- case XK_l:
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- needDisplay = GL_TRUE;
- break;
- case XK_C:
- case XK_c:
- RotateColorMask();
- needDisplay = GL_TRUE;
- break;
- case XK_B:
- case XK_b:
- switch(drawBuffer) {
- case GL_FRONT:
- drawBuffer = GL_NONE;
- printf("Drawing to GL_NONE.\n");
- break;
- case GL_NONE:
- drawBuffer = GL_FRONT;
- printf("Drawing to GL_FRONT.\n");
- break;
- }
- needDisplay = GL_TRUE;
- break;
- case XK_R:
- case XK_r:
- randomVertex = 1-randomVertex;
- needDisplay = GL_TRUE;
- break;
- case XK_Q:
- case XK_q:
- clipped = 1-clipped;
- fastest2D = 0;
- needDisplay = GL_TRUE;
- break;
- case XK_2:
- fastest2D = 1-fastest2D;
- clipped = 0;
- needDisplay = GL_TRUE;
- break;
- case XK_Escape:
- return 0;
- }
- }
- break;
- }
- } while (XPending(dpy) != 0);
-
- if (needDisplay) {
- needDisplay = GL_FALSE;
- DoTests();
- }
- }
- }
-